package com.wan.zuochengyun_v2.stack_queue;

import java.util.LinkedList;

public class MyDequeue<T> {
    private LinkedList<T> deque;

    public MyDequeue() {
        this.deque = new LinkedList();
    }

    /**
     * 入队，list头部入队
     */
    public boolean offerFirst(T val) {
        return deque.offerFirst(val);
    }

    /**
     * 入队，list尾部入队
     */
    public boolean offerLast(T val) {
        return deque.offerLast(val);
    }

    /**
     * 出队，list头部出队
     */
    public T pollFirst() {
        return deque.pollFirst();
    }

    /**
     * 出队，list尾部出队
     */
    public T pollLast() {
        return deque.pollLast();
    }

    public T head() {
        return deque.peekFirst();
    }

    public T tail() {
        return deque.peekLast();
    }

    public int size() {
        return deque.size();
    }

    public static void main(String[] args) {
        System.out.println("\n************************Deque**********************");
        MyDequeue<Integer> dequeue = new MyDequeue<>();
        System.out.println(dequeue.offerFirst(1));
        System.out.println(dequeue.offerFirst(2));
        System.out.println(dequeue.offerLast(3));
        System.out.println(dequeue.head());
        System.out.println(dequeue.tail());
        for (int i = dequeue.size(); i > 0; i--) {
            System.out.print(dequeue.pollLast() + ",");
//            System.out.println(dequeue.pollFirst() + ",");
        }
    }
}
